package com.slsoft.auth.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/pub")
public class PubAction {
	@RequestMapping("signin")
	public String signin() {
		return "/login";
	}

	@RequestMapping("logout")
	public String logout() {
		return "/logout";
	}
	/**
	 * 会话过期跳转处理
	 * @param request
	 * @param response
	 * @return
	 */
   @RequestMapping("/sessionTimeOut")
	public String  sessionTimeOut(HttpServletRequest request,HttpServletResponse response){
		return sendError(request, response,"noSession");
		
	}

	
	/**
	 * session同步出错处理
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/sessionInvalid")
	public String sessionInvalid(HttpServletRequest request,HttpServletResponse response){
		return sendError(request, response,"sessionInvalid");
	
	}
	
	private String sendError(HttpServletRequest request,
			HttpServletResponse response,String tag) {
		String ajaxHeader = request.getHeader("X-Requested-With");
		if ((ajaxHeader != null) && (ajaxHeader.equalsIgnoreCase("XMLHttpRequest"))) {
			response.addHeader("loginStatus", tag);
			return null;
		}else{
			return "redirect:/pub/signin.action";
		}
	}
	/**
	 * 无权限处理
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/accessDenied")
	public String accessDenied(HttpServletRequest request,HttpServletResponse response){
		return sendError(request, response,"accessDenied");
	}
	
}
